package com.yzion.baselib.http.interceptor

import com.yzion.baselib.http.RequestHandler
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import java.io.IOException

/**
 * 请求前和响应后的处理拦截器，请看RequestHandler接口
 */
open class RequestHandlerInterceptor(val handler: RequestHandler) : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        var request = chain.request()
        request = handler.onRequest(request, chain)
        val response = chain.proceed(request)
        return handler.onResponse(response, chain)
    }
}